<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<script type="text/javascript">

function addQuestionOption() {
	var checkedVal;
	if($('input[name=option_correct]').attr('checked')==true) {
		checkedVal = 1;
	}
	else {
		checkedVal = 0;
	}
	var optionContent = $('textarea[name=optionContent]').val();
	if (optionContent=="") {
		showError("#optionErrorDiv", "please input option content.");
	}
	else {
		$("#optionCorrect").attr("value",checkedVal);
		$("#add_option_form").submit();
	}
}
function addQuestionSolution() {
	var solutionContent = $('textarea[name=solutionContent]').val();
	if (solutionContent=="") {
		showError("#solutionErrorDiv", "please input solution content.");
	}
	else {
		$("#add_solution_form").submit();
	}
}
function addQuestionSeckill() {
	var seckillContent = $('textarea[name=seckillContent]').val();
	if (seckillContent) {
	}
	else {
		$('#add_seckill_form').submit();
	}
}
function delOptionConfirm(oID, qID){
	var r=confirm("wanna delete Option [" + oID + "]?");
	if (r==true)
	{
		var href = "<%=basePath%>backend/backend.do?action=deleteQuestionOption&optionID=" + oID + "&questionID=" + qID;
		window.location.href = href;
	}
}
function delSolutionConfirm(sID, qID){
	var r=confirm("wanna delete Solution [" + sID + "]?");
	if (r==true)
	{
		var href = "<%=basePath%>backend/backend.do?action=deleteQuestionSolution&solutionID=" + sID + "&questionID=" + qID;
		window.location.href = href;
	}
}
function delSeckillConfirm(seckillID, qID){
	var r=confirm("wanna delete Seckill [" + seckillID + "]?");
	if (r==true)
	{
		var href = "<%=basePath%>backend/backend.do?action=deleteQuestionSeckill&seckillID=" + seckillID + "&questionID=" + qID;
		window.location.href = href;
	}
}
function showError(tDiv, message) {
	$().Message({type:'error', time:2000,text:message, target:tDiv, click:true});
}
</script>
<div id="submenu">
	<div class="modules_left">
		<!-- ******************** 添加选项 ******************* -->
		<div class="module buttons">
			<a href="" class="dropdown_button"><small class="icon plus"></small><span>添加选项</span></a>
			<div class="dropdown">
				<div class="arrow"></div>
				<div class="content">
					<form id='add_option_form' name='add_option_form' action="<%=basePath%>backend/backend.do?action=addQuestionOption" method='POST'>
						<input type="hidden" id="question_id" name="question_id" value="${question.id}">
						<input type="hidden" id="optionCorrect" name="optionCorrect">
							<div id="optionErrorDiv">
							</div>
						<p>
							<label for="simple_input">选项内容:</label>
							<textarea id="optionContent" name="optionContent" rows="10" cols="35"></textarea>
						</p>
						<p class="small"></p>
						<br />
						<p>
							<label for="simple_input">是否是正确答案:</label>
							<input type="checkbox" class="checkbox" id="option_correct" name="option_correct" checked="checked">
						</p>
						<br />
						<p class="small"></p>
						
					</form>
					<a href="javascript:addQuestionOption();" class="button green right"><small class="icon check"></small><span>Save</span></a>
					<a class="button red mr right close"><small class="icon cross"></small><span>Close</span></a>
					<div class="clear"></div>
				</div>
			</div>
		</div>
		<!-- ******************** 添加解题技巧 ******************* -->
		<div class="module buttons">
			<a href="" class="dropdown_button"><small class="icon plus"></small><span>添加解决方案</span></a>
			<div class="dropdown">
				<div class="arrow"></div>
				<div class="content">
					<form id='add_solution_form' name='add_solution_form' action="<%=basePath%>backend/backend.do?action=addQuestionSolution" method='POST'>
						<input type="hidden" id="question_id" name="question_id" value="${question.id}">
						<div id="solutionErrorDiv">
						</div>
						<p>
							<label for="simple_input">解决方案:</label>
							<textarea id="solutionContent" name="solutionContent" rows="10" cols="35"></textarea>
						</p>
						<p class="small"></p>
					</form>
					<a href="javascript:addQuestionSolution();" class="button green right"><small class="icon check"></small><span>Save</span></a>
					<a class="button red mr right close"><small class="icon cross"></small><span>Close</span></a>
					<div class="clear"></div>
				</div>
			</div>
		</div>
		<!-- ******************** 添加秒杀 ******************* -->
		<div class="module buttons">
			<a href="" class="dropdown_button"><small class="icon plus"></small><span>添加秒杀</span></a>
			<div class="dropdown">
				<div class="arrow"></div>
				<div class="content">
					<form id='add_seckill_form' name='add_seckill_form' action="<%=basePath%>backend/backend.do?action=addQuestionSeckill" method='POST'>
						<input type="hidden" id="question_id" name="question_id" value="${question.id}">
						<div id="seckillErrorDiv">
						</div>
						<p>
							<label for="simple_input">秒杀技巧:</label>
							<textarea id="seckillContent" name="seckillContent" rows="10" cols="35"></textarea>
						</p>
						<p class="small"></p>
						
					</form>
					<a href="javascript:addQuestionSeckill();" class="button green right"><small class="icon check"></small><span>Save</span></a>
					<a class="button red mr right close"><small class="icon cross"></small><span>Close</span></a>
					<div class="clear"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="col w5">
	<div class="content">
		<div class="box">
			<div class="head"><div></div></div>
			<h2>题干:</h2>
			<div class="desc">
				<p>
					<c:out value="${question.questionTitle}" />
				</p>
			</div>
			<div class="bottom"><div></div></div>
		</div>
		<div class="box">
			<div class="head"><div></div></div>
			<h2>选项:</h2>
			<div class="desc">
				<c:forEach var="options" items="${question.ocQuestionOptions}">
					<div class="col w10">
					<br>
						<p>
							<c:choose>
								<c:when test="${options.optionCorrect == '0'}">
									<img src="<%=basePath%>images/answer_judge_false_normal.png" width="12px" height="12px" alt="correct answer" />
									<c:out value="${options.optionContent}" />
									<a href="javascript:delOptionConfirm('${options.id}', '${question.id}');"><span>删除</span></a>
									<a href="<%=basePath%>backend/backend.do?action=modifyQuestionOptionCorrect&optionID=${options.id}&questionID=${question.id}"><span>修改为正确</span></a>
								</c:when>
								<c:when test="${options.optionCorrect == '1'}">
									<img src="<%=basePath%>images/answer_judge_true_normal.png" width="14px" height="14px" alt="correct answer" />
									<small class="icon classname"></small><c:out value="${options.optionContent}" />
									<a href="javascript:delOptionConfirm('${options.id}', '${question.id}');"><span>删除</span></a>
									<a href="<%=basePath%>backend/backend.do?action=modifyQuestionOptionFault&optionID=${options.id}&questionID=${question.id}"><span>修改为错误</span></a>
								</c:when>
							</c:choose>
						</p>
					</div>
				</c:forEach>
			</div>
			<div class="bottom"><div></div></div>
		</div>
	</div>
</div>
<div class="col w5 last">
	<div class="content">
		<div class="box">
			<div class="head"><div></div></div>
			<h2>解题技巧:</h2>
			<div class="desc">
				<c:forEach var="solutions" items="${question.ocQuestionSolutions}">
					<div class="col w10">
					<br>
						<p>
							<c:out value="${solutions.solutionContent}" />
							<a href="javascript:delSolutionConfirm('${solutions.id}', '${question.id}');"><span>删除</span></a>
						</p>
					</div>
				</c:forEach>
			</div>
			<div class="bottom"><div></div></div>
		</div>
		
		<div class="clear"></div>
		
		<div class="box">
			<div class="head"><div></div></div>
			<h2>秒杀:</h2>
			<div class="desc">
				<c:forEach var="seckills" items="${question.ocQuestionSeckills}">
					<div class="col w10">
					<br>
						<p>
							<c:out value="${seckills.seckillContent}" />
							<a href="javascript:delSeckillConfirm('${seckills.id}', '${question.id}');"><span>删除</span></a>
						</p>
					</div>
				</c:forEach>
			</div>
			<div class="bottom"><div></div></div>
		</div>
	</div>
</div>
<div class="clear"></div>